<template>
    <div>
        {{ info  }}
        <table class="table table-brodered ">
            <thead>
                <tr>
                    <td>门店名称</td>
                    <td><input type="text" v-model="info.nName" ></td>
                </tr>

                <tr>
                    <td>分店名称</td>
                    <td><input type="text" v-model="info.fName" ></td>
                </tr>

                <tr>
                    <td>商户地址</td>
                    <td><select  v-model="info.aid" >
                        <option value="0">请选择</option>
                        <option :value="o.aid" v-for="o in vou"  >{{ o.aName }}</option>
                    </select></td>
                </tr>

                <tr>
                    <td>图片</td>
                    <td><input type="file" @change="img" >
                        <img :src="info.fImg" width="60" height="60"  ></td>
                </tr>

                <tr>
                    <td>电话</td>
                    <td><input type="text" v-model="info.phone" ></td>
                </tr>
                <tr>
                    <td>门店介绍</td>
                    <td><textarea  v-model="info.menjie" ></textarea></td>
                </tr>
                <tr>
                    <td>入店须知</td>
                    <td><textarea  v-model="info.menR" ></textarea></td>
                </tr>
                <tr>
                    <td>交通信息</td>
                    <td><textarea  v-model="info.menXin" ></textarea></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="Add"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const router=useRouter();
const route=useRoute();

let vou:any=ref([]);

let info:any=ref({
  "fId":route.query.id,
  "nName": "",
  "fName": "",
  "aid": "0",
  "fImg": "",
  "phone": "",
  "state": 0,
  "menjie": "",
  "menR": "",
  "menXin": "",
  "isDell": 0
})

onMounted(()=>{
    List();
    Fand();
} )

const Fand=()=>{
    axios({
        url:'https://localhost:7124/api/User/Fand',
        method:'post',
        params:{
            id:route.query.id
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(info.value ,res.data );
    } )
}


const List=()=>{
    axios({
        url:'https://localhost:7124/api/User/List',
        method:'get',
    })
    .then((res)=>{
        console.log(res);
        vou.value=res.data;
    })
}

const img=(e:any)=>{
    let obj=e.target.files[0];
    let f=new FormData();
    f.append("file",obj);
    axios({
        url:"https://localhost:7124/api/Img",
        method:'post',
        data:f
    })
    .then((res)=>{
        console.log(res);
        info.value.fImg=res.data;
    })
}


const Add=()=>{
    let f=confirm("要修改吗");
    if(f){
        axios({
        url:'https://localhost:7124/api/User/Updata',
        method:'post',
        data:info.value
    })
    .then((res)=>{
        console.log(res);
        
        if(res.data>0 )
    {
        alert("成功");
        
    }
    })
    }

    
    
}


</script>

<style scoped>

</style>